package segger.vasttrafik;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;


public class TimeTable {

    private ArrayList<Tram> trams;

    public TimeTable() {
        trams = new ArrayList<Tram>();
    }
    
    public void add(Tram tram) {
        trams.add(tram);
    }

    public ArrayList<Tram> getAllTrams() {
        return trams;
    }
    
    public ArrayList<Tram> getAllTrams(Comparator<Tram> comparator) {
        ArrayList<Tram> copy = copy();
        Collections.sort(copy, comparator);
        return copy;
    }
    
    private ArrayList<Tram> copy() {
        ArrayList<Tram> tmp = new ArrayList<Tram>();
        for(Tram tram : trams) {
            tmp.add(tram);
        }
        return tmp;
    }

}
